package private1;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;

public class Day {
    private int year=1;//字段
    private int month=1;
    private int date=1;

    static {//类初始化器
        GregorianCalendar today=new GregorianCalendar();
        int y=today.get(Calendar.YEAR);
        int m=today.get(Calendar.MONTH)+1;
        int d=today.get(Calendar.DATE);
        System.out.printf("今天是%04d年%02d月%02d日。\n",y,m,d);
//        Scanner stdIn=new Scanner(System.in);
//        int n=stdIn.nextInt();
//        if (n>12)
//            break;
//        else {
//          public Day( int year, int month){
//                this(year);
//                this.month = month;
//                //set(year, month, 1);
//            }
//
//        }
    }


    public static boolean isLeap(int y){
        return y%4==0&&y%100!=0||y%400==0;

    }

    //public   Day(int year,int month,int date){
//        this.year=year;
//        this.month=month;
//        this.date=date;
//    }
//    public static boolean isLeap(int y){
//        return y%4==0&&y%100!=0||y%400==0;
//    }//以下为构造函数
//

    public Day() {
       // set(1, 1, 1);
         }

    public Day(int year) {

        this.year=year;
        //set(year, 1, 1);
    }

    public Day(int year, int month) {
        this(year);
        this.month=month;
        //set(year, month, 1);
    }

    public Day(int year, int month, int date) {
        this(year,month);
        this.date=date;
        //set(year, month, date);
    }

    public Day(Day d) {//复制构造函数，不用构造函数，使用Clone方法也可以实现
        this(d.year,d.month,d.date);
        //set(d.year, d.month, d.date);
    }


    //---获取年、月、日---//下面为方法
    public int getYear() {
        return year;
    }

    public int getMonth() {
        return month;
    }

    public int getDate() {
        return date;
    }


    public void setYear(int year) {
        this.year = year;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public void setDate(int date) {
        this.date = date;
    }





    public void set(int year, int month, int date) {
        this.year = year;
        this.month = month;
        this.date = date;
    }


    public boolean isLeap(){
        return isLeap(year);
    }



    //设置星期
    public int dayOfWeek() {
        int y = year;
        int m = month;
        if (m == 1 || m == 2) {
            y--;
            m += 12;
        }
        return (y + y / 4 - y / 100 + y / 400 + (13 * m + 8) / 5 + date) % 7;//泰勒公式计算法，以格里高历利为前提的，只能计算1582年10月15日之后的日期所对应的星期
    }

    //与日期d相等吗
    public boolean equalTo(Day d){//比较所有字段的值是否相等
        return year==d.year&&
                month==d.month&&date==d.date;
    }
    //返回字符串表示，显示程序要一句
    public String toString(){
        String[] wd={"日","一","二","三","四","五","六",};
        return String.format("%04d年%02d月%02d日(%s)",year,month,date,wd[dayOfWeek()]);
    }


}
